1 module hip.image_backend.arsd; 2 import hip.api.data.image; 3 4 5 version(HipARSDImageDecoder) 6 final class HipARSDImageDecoder : IHipAnyImageDecoder 7 { 8 import arsd.image; 9 private 10 { 11 MemoryImage img; 12 TrueColorImage trueImg; 13 } 14 string path; 15 this(string path = "") 16 { 17 this.path = path; 18 } 19 bool startDecoding(ubyte[] data, void delegate() onSuccess, void delegate() onFailure) 20 { 21 img = loadImageFromMemory(data); 22 if(img !is null) 23 { 24 trueImg = img.getAsTrueColorImage; 25 onSuccess(); 26 } 27 else 28 onFailure(); 29 30 return (img !is null) && (trueImg !is null); 31 } 32 33 uint getWidth() const 34 { 35 if(img !is null) 36 return img.width; 37 return 0; 38 } 39 40 uint getHeight() const 41 { 42 if(img !is null) 43 return img.height; 44 return 0; 45 } 46 47 const(ubyte[]) getPixels() const 48 { 49 if(img !is null) 50 return trueImg.imageData.bytes; 51 return null; 52 } 53 54 ubyte getBytesPerPixel() const 55 { 56 //Every true image color has 4 bytes per pixel 57 return 4; 58 } 59 60 ubyte[] getPalette() const 61 { 62 return null; 63 } 64 65 void dispose() 66 { 67 img.clearInternal; 68 destroy(trueImg); 69 destroy(img); 70 } 71 }